<template>
  <div>
    <nav-com
      title="公告详情"
      :showView='true'
      @back="backHandler()"
    ></nav-com>
    <h2 style="text-align:center;padding:0 5vw">{{details.title}}</h2>
    <h5 style="text-align:center;color:#ccc">{{details.createtime | formData}}</h5>
    <div v-html='details.content' class="main"></div>
    <div style="margin-top:15vw">
      <div style="color:rgba(0,0,0,0)">1</div>
      <div v-if="lastNotice!=null">
          <div class="other" @click="change(lastNotice.id)">上一篇：{{lastNotice.title}}</div>
      </div>
      <div v-if="nextNotice!=null" >
          <div class="other" @click="change(nextNotice.id)">下一篇：{{nextNotice.title}}</div>
      </div>
      <div style="color:rgba(0,0,0,0)">1</div><div style="color:rgba(0,0,0,0)">1</div>
    </div>
  </div>
</template>

<script>
import navCom from "@/component/nav";
import { getNoticeDetail, noticeLook } from "@/api/api";
import moment from 'moment';
export default {
  components: {
    navCom,
  },
  filters:{
    formData(val){
      return moment(val*1000).format("YYYY-MM-DD hh:mm:ss")
    }
  },
  data() {
    return {
      details: {},
      nextNotice:{},
      lastNotice:{}
    };
  },
  created(){
    console.log(this.$route)
    let id = this.$route.params.id
    this.initData(id)
    this.looked(id)
  },
  methods:{
    looked(id){
      noticeLook({id}).then(res>{})
    },
    change(id){
      this.initData(id)
      this.looked(id)
    },
    //返回
    backHandler() {
      this.$router.go(-1);
    },
    initData(id){
      getNoticeDetail({id}).then((result) => {
        if(result.data.code == 1){
          this.details = result.data.data.info
          this.nextNotice = result.data.data.low
          this.lastNotice = result.data.data.up
          console.log(this.nextNotice,this.lastNotice)
        }
      }).catch((err) => {
        
      });
    }
  },
};
</script>

<style scoped>
.other{
  height: 5vw;
  line-height: 5vw;
  color: #ccc;
  font-size: 3.83vw;
  margin: 3vw;
  text-decoration:underline;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.main{
  width: 100vw;
}
.main >>> img {
  display: block;
  width: 100%;
  height: auto;
  float: left;
}
</style>